Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
The js-md5 npm package is a lightweight JavaScript library used to generate MD5 hashes. It is commonly used for hashing strings, files, and other data types to ensure data integrity, create unique identifiers, and for cryptographic purposes.
Hashing a String
This feature allows you to generate an MD5 hash from a given string. The code sample demonstrates how to hash the string 'Hello, World!' and output the resulting hash.
const md5 = require('js-md5');
const hash = md5('Hello, World!');
console.log(hash); // Outputs: '65a8e27d8879283831b664bd8b7f0ad4'
Hashing a File
This feature allows you to generate an MD5 hash from a file. The code sample demonstrates how to read a file into a buffer and then hash its contents.
const md5 = require('js-md5');
const fs = require('fs');
const fileBuffer = fs.readFileSync('path/to/file.txt');
const hash = md5(fileBuffer);
console.log(hash);
Hashing an ArrayBuffer
This feature allows you to generate an MD5 hash from an ArrayBuffer. The code sample demonstrates how to create an ArrayBuffer, populate it with data, and then hash its contents.
const md5 = require('js-md5');
const buffer = new ArrayBuffer(8);
const view = new Uint8Array(buffer);
view[0] = 0x01;
view[1] = 0x02;
const hash = md5(buffer);
console.log(hash);
Crypto-js is a widely-used library that provides a variety of cryptographic algorithms, including MD5, SHA-1, SHA-256, and more. It is more comprehensive than js-md5, offering a broader range of cryptographic functionalities.
The md5 package is another popular library for generating MD5 hashes. It is similar to js-md5 in terms of functionality but is often preferred for its simplicity and ease of use.
Hash.js is a library that provides a variety of hash functions, including MD5, SHA-1, and SHA-256. It is known for its performance and flexibility, making it a good alternative to js-md5 for more complex hashing needs.
A simple MD5 hash function for JavaScript supports UTF-8 encoding.
MD5 Online
MD5 File Checksum Online
You can also install js-md5 by using Bower.
bower install md5
For node.js, you can use this command to install:
npm install js-md5
buffer
method is deprecated. This maybe confuse with Buffer in node.js. Please use arrayBuffer
instead.
You could use like this:
md5('Message to hash');
var hash = md5.create();
hash.update('Message to hash');
hash.hex();
If you use node.js, you should require the module first:
md5 = require('js-md5');
It supports AMD:
require(['your/path/md5.js'], function(md5) {
// ...
});
md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
// It also supports UTF-8 encoding
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
md5([]); // d41d8cd98f00b204e9800998ecf8427e
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
// Different output
md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
md5.arrayBuffer(''); // ArrayBuffer
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==
The project is released under the MIT license.
The project's website is located at https://github.com/emn178/js-md5
Author: Chen, Yi-Cyuan (emn178@gmail.com)
v0.7.3 / 2017-12-18
FAQs
A simple MD5 hash function for JavaScript supports UTF-8 encoding.
The npm package js-md5 receives a total of 95,199 weekly downloads. As such, js-md5 popularity was classified as popular.
We found that js-md5 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.